package com.warm.system.controller.system;

import cn.dev33.satoken.annotation.SaIgnore;
import com.warm.core.domain.AjaxResult;
import com.warm.core.utils.StringUtils;
import com.warm.mybatis.core.controller.BaseController;
import com.warm.system.api.model.RegisterBody;
import com.warm.system.service.ISysConfigService;
import com.warm.system.service.SysRegisterService;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Inject;
import org.noear.solon.annotation.Mapping;
import org.noear.solon.annotation.Post;
import org.noear.solon.validation.annotation.Valid;

/**
 * 注册验证
 *
 * @author warm
 */
@Valid
@Controller
public class SysRegisterController extends BaseController {
    @Inject
    private SysRegisterService registerService;

    @Inject
    private ISysConfigService configService;

    @SaIgnore
    @Post
    @Mapping("/register")
    public AjaxResult register(RegisterBody user) {
        if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) {
            return error("当前系统没有开启注册功能！");
        }
        String msg = registerService.register(user);
        return StringUtils.isEmpty(msg) ? success() : error(msg);
    }
}
